﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 系统设置
{
    public partial class DynSet : Form
    {
        carinfor.equipmentConfigInfdata equipconfig = new carinfor.equipmentConfigInfdata();
        carinfor.configIni configini = new carinfor.configIni();
        public DynSet()
        {
            InitializeComponent();
        }

        private void DynSet_Load(object sender, EventArgs e)
        {
            equipconfig = configini.getEquipConfigIni();
            
            if (equipconfig.Cgjifpz == false)
                comboBoxCgjxh.Text = "无";
            else
                comboBoxCgjxh.Text = equipconfig.Cgjxh;
            comboBoxDYNVersion.Text = equipconfig.igbtVersion;
            
            comboBoxCgjck.Text = equipconfig.Cgjck;            
            comboBoxCgjckpzz.Text = equipconfig.cgjckpzz;            
            textBoxBrakePWM.Text = equipconfig.BrakePWM.ToString();
            textBoxCgjR.Text = equipconfig.CGJR.ToString("0");
            comboBoxEddyCount.SelectedIndex=equipconfig.eddycount-1;
            textBoxForceFull.Text= equipconfig.forceFull.ToString();
            textBoxForceRatio.Text= equipconfig.forceRatio.ToString("0.0");

            comboBoxBPQMODE.SelectedIndex= equipconfig.bpqcontrolmode ;
            comboBoxBPQXH.Text= equipconfig.bpqxh ;
            comboBoxBPQCOM.Text= equipconfig.bpqcom;
            comboBoxBPQCOMPZ.Text = equipconfig.bpqcompz;
            comboBoxBPQXS.Text= equipconfig.bpqxs.ToString("0.000") ;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            carinfor.equipmentConfigInfdata equipconfigtosave = new carinfor.equipmentConfigInfdata().CopyFrom(equipconfig);
            //carinfor.RotateConfigData rotateconfig = configini.getRotateConfigIni();
            equipconfigtosave.igbtVersion = comboBoxDYNVersion.Text;
            if (comboBoxCgjxh.Text == "无")
                equipconfigtosave.Cgjifpz = false;
            else
            {
                equipconfigtosave.Cgjifpz = true;
                equipconfigtosave.Cgjxh = comboBoxCgjxh.Text;
                equipconfigtosave.Cgjck = comboBoxCgjck.Text;
            }
           
            equipconfigtosave.BrakePWM = int.Parse(textBoxBrakePWM.Text);
            
            equipconfigtosave.cgjckpzz = comboBoxCgjckpzz.Text;
            equipconfigtosave.CGJR = int.Parse(textBoxCgjR.Text);
            equipconfigtosave.eddycount =comboBoxEddyCount.SelectedIndex+1;
            equipconfigtosave.forceFull = int.Parse(textBoxForceFull.Text);
            equipconfigtosave.forceRatio = double.Parse(textBoxForceRatio.Text);


            equipconfigtosave.bpqcontrolmode = comboBoxBPQMODE.SelectedIndex;
            equipconfigtosave.bpqxh = comboBoxBPQXH.Text;
            equipconfigtosave.bpqcom = comboBoxBPQCOM.Text;
            equipconfigtosave.bpqcompz = comboBoxBPQCOMPZ.Text;
            equipconfigtosave.bpqxs = double.Parse(comboBoxBPQXS.Text);
            settingform.saveLog("检测配置参数", equipconfig, equipconfigtosave);
            
            if (configini.writeEquipmentConfig(equipconfigtosave))
                MessageBox.Show("保存成功.", "系统提示");
            else
                MessageBox.Show("数据输入有误,请检查.", "未成功保存");
        }
    }
}
